package com.estar.assistsurvy.fragment;

import java.util.ArrayList;

import com.estar.assistsurvy.R;
import com.estar.assistsurvy.entity.ScalePagerItem;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

public class CarLeftFragment extends BaseFragment implements OnClickListener{

	private Button frontBumper,frontMachineCover,carTop,leftFrontFender,
	leftFrontDoor,leftBackDoor,leftBackFender;
	private boolean isclick1=false,isclick2=false,isclick3=false,isclick4=false,isclick5=false,isclick6=false,isclick7=false;
	private ArrayList<ScalePagerItem> list;
	private ScalePagerItem item1,item2,item3,item4,item5,item6,item7;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		if(view==null){
			view=inflater.inflate(R.layout.fragment_carleft, null);
		}
		return view;
	}

	@Override
	public void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		initView();
	}

	private void initView(){
		frontBumper=find(R.id.frontBumper);
		frontBumper.setOnClickListener(this);
		frontMachineCover=find(R.id.frontMachineCover);
		frontMachineCover.setOnClickListener(this);
		carTop=find(R.id.carTop);
		carTop.setOnClickListener(this);
		leftFrontFender=find(R.id.leftFrontFender);
		leftFrontFender.setOnClickListener(this);
		leftFrontDoor=find(R.id.leftFrontDoor);
		leftFrontDoor.setOnClickListener(this);
		leftBackDoor=find(R.id.leftBackDoor);
		leftBackDoor.setOnClickListener(this);
		leftBackFender=find(R.id.leftBackFender);
		leftBackFender.setOnClickListener(this);
		list=new ArrayList<>();
		item1=new ScalePagerItem();
		item1.setTitles("前杠");
		item1.setScaleImages(R.drawable.pic_car01);
		item2=new ScalePagerItem();
		item2.setTitles("前机盖");
		item2.setScaleImages(R.drawable.pic_car02);
		item3=new ScalePagerItem();
		item3.setTitles("车顶");
		item3.setScaleImages(R.drawable.pic_car03);
		item4=new ScalePagerItem();
		item4.setTitles("左前叶子板");
		item4.setScaleImages(R.drawable.pic_car04);
		item5=new ScalePagerItem();
		item5.setTitles("左前门");
		item5.setScaleImages(R.drawable.pic_car05);
		item6=new ScalePagerItem();
		item6.setTitles("左后门");
		item6.setScaleImages(R.drawable.pic_car06);
		item7=new ScalePagerItem();
		item7.setTitles("左后叶子板");
		item7.setScaleImages(R.drawable.pic_car07);
	}
	
	public ArrayList<ScalePagerItem> getList(){
		return list;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.frontBumper:
			if(isclick1){
				isclick1=false;
				list.remove(item1);
				frontBumper.setBackgroundResource(R.drawable.demaged_frame);
				frontBumper.setTextColor(getActivity().getResources().getColor(R.color.colorTextOrange));
			}else{
				isclick1=true;
				list.add(item1);
				frontBumper.setBackgroundResource(R.drawable.demaged_frame1);
				frontBumper.setTextColor(getActivity().getResources().getColor(R.color.colorBgWhite));
			}
			
			break;

		case R.id.frontMachineCover:
			if(isclick2){
				isclick2=false;
				list.remove(item2);
				frontMachineCover.setBackgroundResource(R.drawable.demaged_frame);
				frontMachineCover.setTextColor(getActivity().getResources().getColor(R.color.colorTextOrange));
			}else{
				isclick2=true;
				list.add(item2);
				frontMachineCover.setBackgroundResource(R.drawable.demaged_frame1);
				frontMachineCover.setTextColor(getActivity().getResources().getColor(R.color.colorBgWhite));
			}
			break;

		case R.id.carTop:
			if(isclick3){
				isclick3=false;
				list.remove(item3);
				carTop.setBackgroundResource(R.drawable.demaged_frame);
				carTop.setTextColor(getActivity().getResources().getColor(R.color.colorTextOrange));
			}else{
				isclick3=true;
				list.add(item3);
				carTop.setBackgroundResource(R.drawable.demaged_frame1);
				carTop.setTextColor(getActivity().getResources().getColor(R.color.colorBgWhite));
			}
			break;

		case R.id.leftFrontFender:
			if(isclick4){
				isclick4=false;
				list.remove(item4);
				leftFrontFender.setBackgroundResource(R.drawable.demaged_frame);
				leftFrontFender.setTextColor(getActivity().getResources().getColor(R.color.colorTextOrange));
			}else{
				isclick4=true;
				list.add(item4);
				leftFrontFender.setBackgroundResource(R.drawable.demaged_frame1);
				leftFrontFender.setTextColor(getActivity().getResources().getColor(R.color.colorBgWhite));
			}
			break;

		case R.id.leftFrontDoor:
			if(isclick5){
				isclick5=false;
				list.remove(item5);
				leftFrontDoor.setBackgroundResource(R.drawable.demaged_frame);
				leftFrontDoor.setTextColor(getActivity().getResources().getColor(R.color.colorTextOrange));
			}else{
				isclick5=true;
				list.add(item5);
				leftFrontDoor.setBackgroundResource(R.drawable.demaged_frame1);
				leftFrontDoor.setTextColor(getActivity().getResources().getColor(R.color.colorBgWhite));
			}
			break;

		case R.id.leftBackDoor:
			if(isclick6){
				isclick6=false;
				list.remove(item6);
				leftBackDoor.setBackgroundResource(R.drawable.demaged_frame);
				leftBackDoor.setTextColor(getActivity().getResources().getColor(R.color.colorTextOrange));
			}else{
				isclick6=true;
				list.add(item6);
				leftBackDoor.setBackgroundResource(R.drawable.demaged_frame1);
				leftBackDoor.setTextColor(getActivity().getResources().getColor(R.color.colorBgWhite));
			}
			break;

		case R.id.leftBackFender:
			if(isclick7){
				isclick7=false;
				list.remove(item7);
				leftBackFender.setBackgroundResource(R.drawable.demaged_frame);
				leftBackFender.setTextColor(getActivity().getResources().getColor(R.color.colorTextOrange));
			}else{
				isclick7=true;
				list.add(item7);
				leftBackFender.setBackgroundResource(R.drawable.demaged_frame1);
				leftBackFender.setTextColor(getActivity().getResources().getColor(R.color.colorBgWhite));
			}
			break;

		default:
			break;
		}
	}
}
